script_enemy_main{

let effect1=0;
let object1=[];
let xscale1=0.01;
let yscale1=0.01;
let xscale2=0.01;
let yscale2=0.01;

let shoottime=240;
let finalshot=0;

let shot1=0;
let bullet1=[];
let timer1=[];
let timer2=[];
let size1=[];
let speed1=[];
let bounce1=[];

let character="Tomoko";
let cutin=character;
let dispelled=0;
let spellcards=7;
let spellcardnumber=36;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=150;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshots5=("script\SoundEffects\shots5.wav");
let SEmagics5=("script\SoundEffects\magics5.wav");

let EFwings=("\script\Images\OtherEffects\ButterflyWings.png");

let BG1=("\script\Images\BackgroundLayers\Tomoko6.png");
let BG2=("\script\Images\BackgroundLayers\Tomoko1.png");
let GRboss=("\script\Images\CharacterSprites\Tomoko.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsTomoko1.txt");

	LoadSE("script\SoundEffects\shots5.wav");
	LoadSE("script\SoundEffects\magics5.wav");

	LoadGraphic("\script\Images\OtherEffects\ButterflyWings.png");
	LoadGraphic("\script\Images\BackgroundLayers\Tomoko6.png");
	LoadGraphic("\script\Images\BackgroundLayers\Tomoko1.png");
	
	LoadGraphic("\script\Images\CharacterSprites\Tomoko.png");

	SetScore(350000);
	SetLife(500);
	SetTimer(50);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(32,32,32,32);

let weaken=1;
if(GetCommonData("BombOn")==0){ if(GetPlayerY<cy){ damagerate=10; } if(GetPlayerY>=cy){ damagerate=20; } }
if(GetCommonData("BombOn")==1){ damagerate=8; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }
SpellcardName("Heredity [Primordial Soup] ("~difficulty~")",spellcardnumber);

HealthBar();
Portrait(cutin,3);

if(time%200==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,miny+120),1.5);
	}
}

if(time==60){
	loop(2){
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetX,GetY);
	ObjEffect_SetScale(effect1,xscale1,yscale1);
	ObjEffect_SetLayer(effect1,1); ObjEffect_SetTexture(effect1,EFwings); ObjEffect_SetRenderState(effect1,ADD);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-190,-100); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,190,-100); ObjEffect_SetVertexUV(effect1,1,380,0);
	ObjEffect_SetVertexXY(effect1,2,-190,100); ObjEffect_SetVertexUV(effect1,2,0,200);
	ObjEffect_SetVertexXY(effect1,3,190,100); ObjEffect_SetVertexUV(effect1,3,380,200);
	ObjEffect_SetVertexColor(effect1,0,180,255,255,255); ObjEffect_SetVertexColor(effect1,1,180,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,180,255,255,255); ObjEffect_SetVertexColor(effect1,3,180,255,255,255);
	object1=object1~[effect1];
	}
}

if(time>=60){
	if(xscale1<1){ xscale1+=(xscale1*0.1); }
	if(yscale1<1){ yscale1+=(yscale1*0.2); }
	if(xscale2<1.1){ xscale2+=(xscale2*0.09); }
	if(yscale2<1.2){ yscale2+=(yscale2*0.18); }
	Obj_SetPosition(object1[0],GetX,GetY-30);
	ObjEffect_SetScale(object1[0],xscale1,yscale1);
	ObjEffect_SetVertexColor(object1[0],0,200,0,255,255); ObjEffect_SetVertexColor(object1[0],1,200,0,255,255);
	ObjEffect_SetVertexColor(object1[0],2,200,255,255,255); ObjEffect_SetVertexColor(object1[0],3,200,255,255,255);
	Obj_SetPosition(object1[1],GetX,GetY-30);
	ObjEffect_SetScale(object1[1],xscale2+0.1*cos(time*2),yscale2+0.2*cos(time*2));
	ObjEffect_SetVertexColor(object1[1],0,200,255,100,255); ObjEffect_SetVertexColor(object1[1],1,200,255,100,255);
	ObjEffect_SetVertexColor(object1[1],2,50,255,100,255); ObjEffect_SetVertexColor(object1[1],3,50,255,100,255);
}


if(frame==shoottime){
let angle=GetAngleToPlayer;
	loop(13){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,1.5);
	ObjShot_SetBombResist(shot1,true);
	Obj_SetAlpha(shot1,0);
	Obj_SetCollisionToPlayer(shot1,false);
	ObjShot_SetGraphic(shot1,1);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1]; timer1[length(bullet1)-1]=0;
	timer2=timer2~[shot1]; timer2[length(bullet1)-1]=rand_int(0,180);
	size1=size1~[shot1]; size1[length(bullet1)-1]=0;
	speed1=speed1~[shot1]; speed1[length(bullet1)-1]=1.5;
	bounce1=bounce1~[shot1]; bounce1[length(bullet1)-1]=0;
	angle+=360/13;
	}
if(shoottime>160){ shoottime-=8; }
frame=0;
}

if(time>=60){
let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){
		bullet1=erase(bullet1,i); timer1=erase(timer1,i); timer2=erase(timer2,i); size1=erase(size1,i);
		speed1=erase(speed1,i); bounce1=erase(bounce1,i);
		i--;
		}
		else{
	if(time%2==0){
	let radius=0+size1[i]*cos(timer2[i]);
	CreateShotA(shot1,Obj_GetX(bullet1[i])+radius*cos(Obj_GetAngle(bullet1[i])+90),Obj_GetY(bullet1[i])+radius*sin(Obj_GetAngle(bullet1[i])+90),10);
	SetShotDataA(shot1,0,0,Obj_GetAngle(bullet1[i])+180-45*cos(timer2[i]),0,0,0,145);
	SetShotDataA(shot1,10,0,Obj_GetAngle(bullet1[i])+180-45*cos(timer2[i]),0,0.01,0.5,131);
	SetShotKillTime(shot1,60);
	FireShot(shot1);
	CreateShotA(shot1,Obj_GetX(bullet1[i])+radius*cos(Obj_GetAngle(bullet1[i])-90),Obj_GetY(bullet1[i])+radius*sin(Obj_GetAngle(bullet1[i])-90),10);
	SetShotDataA(shot1,0,0,Obj_GetAngle(bullet1[i])+180+45*cos(timer2[i]),0,0,0,152);
	SetShotDataA(shot1,10,0,Obj_GetAngle(bullet1[i])+180+45*cos(timer2[i]),0,0.01,0.5,138);
	SetShotKillTime(shot1,60);
	FireShot(shot1);
	}
	
	if(time%6==0){ PlaySE(SEshots5); }

		if(bounce1[i]<1){
			if(Obj_GetX(bullet1[i])<=minx){
			Obj_SetAngle(bullet1[i],180-Obj_GetAngle(bullet1[i]));
			Obj_SetX(bullet1[i],Obj_GetX(bullet1[i])+Obj_GetSpeed(bullet1[i]));
			bounce1[i]=bounce1[i]+1; PlaySE(SEmagics5);
			}
			if(Obj_GetX(bullet1[i])>=maxx){
			Obj_SetAngle(bullet1[i],180-Obj_GetAngle(bullet1[i]));
			Obj_SetX(bullet1[i],Obj_GetX(bullet1[i])-Obj_GetSpeed(bullet1[i]));
			bounce1[i]=bounce1[i]+1; PlaySE(SEmagics5);
			}
			if(Obj_GetY(bullet1[i])<=miny){
			Obj_SetAngle(bullet1[i],-Obj_GetAngle(bullet1[i]));
			Obj_SetY(bullet1[i],Obj_GetY(bullet1[i])+Obj_GetSpeed(bullet1[i]));
			bounce1[i]=bounce1[i]+1; PlaySE(SEmagics5);
			}
		}
		if(size1[i]<50){ size1[i]=size1[i]+1; }

		timer1[i]=timer1[i]+1;
		timer2[i]=timer2[i]+speed1[i]*1.7;
		}
	i++;
	}
}


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";
}

@BackGround{
	if(bgfade<180){ bgfade+=5; }
	
	SetTexture(BG2);
	SetAlpha(bgfade);
	SetGraphicScale(2,2);
	SetGraphicRect(0,0,350,350);
	SetGraphicAngle(0,0,time/3);
	DrawGraphic(cx,cy-70);

	SetGraphicRect(0,0,300,450);
	SetGraphicScale(1,1);
	SetTexture(BG1);
	SetAlpha(255);
	SetColor(bgfade,bgfade,bgfade);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
//	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}